
<template>
  <div class="app-container">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="比对环境" :label-width="formLabelWidth">
        <el-select v-model="kubes" multiple placeholder="请选择" style="width: 400px">
          <el-option
            v-for="item in kubelist"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item>

        <el-button type="primary" @click="fetchData()">比对</el-button>

      </el-form-item>
      <el-form-item>
        <el-checkbox v-model="samehide">隐藏相同项</el-checkbox>
      </el-form-item>

    </el-form>
    <el-tag type="success">命中条目: {{ tableData.length }}</el-tag>
    <el-table
      :data="tableData"
      style="width: 100%;margin-bottom: 20px;"
      row-key="path"
      border
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      :cell-style="cellStyleHandle"
    >
      <el-table-column
        v-for="(item, index) in tableLabel"
        :key="index"
        :prop="item.prop"
        :label="item.label"
      />

    </el-table>
  </div>
</template>

<script>
import { getTableLabel, getTableData, getKubeData } from '@/api/eff/imagediff'

export default {
  data() {
    return {
      samehide: true,
      tableData: [],
      listLoading: true,
      formLabelWidth: '300px',
      tableLabel: [],
      kubelist: [],
      kubes: []
    }
  },
  created() {
    this.initTableLabel()
    this.fetchKubeData()
  },
  methods: {
    initTableLabel() {
      getTableLabel().then(response => {
        this.tableLabel = response.data
      })
    },
    fetchKubeData() {
      getKubeData().then(response => {
        this.kubelist = response.data
        for (const index in this.kubelist) {
          this.kubes.push(this.kubelist[index].id)
        }
      })
    },
    fetchData() {
      this.listLoading = true
      this.tableData = []
      const params = { 'samehide': this.samehide ? 1 : 0, 'kubes': this.kubes }
      // const params = Object.assign(this.searchParam, { 'start': start, 'end': end })
      getTableData(params).then(response => {
        this.tableData = response.data
        this.listLoading = false
      })
    },
    cellStyleHandle({ row, column, rowIndex, columnIndex }) {
      if (row.diff === 1) {
        return 'background: #ffbf00'
      }
    }
  }
}
</script>

<style>
.demo-form-inline {
  text-align: right
}
</style>
